
<template>
    <div class="personal">
        <div class="top">
            <div>  <span class="iconfont iconjiantou" @click="$router.push('/')"></span> </div>
            <div class="text">个人主页</div>
        </div>
        <div class="box">
            <div class="boxone">
                <div class="message" v-if='perval'>
                    <img v-if='perval.head_img' :src=" $axios.defaults.baseURL + perval.head_img" alt="2" >
                    <img v-else src="@/assets/logo.png" alt="1">
                    <div class="mess" >
                        <span class="iconfont"  :class="perval.gender == 1 ? 'iconxingbienan' : 'iconxingbienv' "></span> <samp>{{perval.nickname}}</samp> <br>
                        <span v-if='perval.create_date'>{{createDate}}</span>
                    </div>
                </div>
            </div>
            <div class="boxtwo">
                <router-link to="./edit"> <span class="iconfont iconjiantou1"></span> </router-link>
            </div>
        </div>
        <personalMod one='我的关注' two='关注的用户' @skip="attention" />
        <personalMod one='我的跟帖' two='跟帖/回复' @skip="myfollow" />
        <personalMod one='我的收藏' two='文章/视频' @skip='collect' />
        <personalMod one='设置' two='' />
        <personalMod one='栏目管理' @skip='column' />
        <personalMod one='退出登录' @skip='logout' />
    </div>
</template>

<script>
import personalMod from '../components/module/personalMod'
export default {
    components:{
        personalMod,
    },
    data(){
        return{
            perval:{}
        }
    },
    computed:{
        createDate(){
            if(this.perval.create_date){
                return this.perval.create_date.split("T")[0]
            }else{
                return '2020-11-09'
            }
        }
    },
    created(){
        this.$axios({  //根据登录id带token获取个人数据
            url:'/user/' + localStorage.getItem('userid'),
            headers: {
                // 在 token 前添加 'Bearer '    注意Bearer  后的空格
                Authorization: 'Bearer '+ localStorage.getItem('token')
            }
        }).then((res)=>{
            console.log(res);
            
            console.log(this.perval);
             if(res.data.message == "用户信息验证失败"){  //添加数据验证失败处理
                 console.log('验证失败');
                 localStorage.removeItem('token')
                 localStorage.removeItem('userid')
             }else{
                this.perval = res.data.data
            }
        })
    },
    methods:{
        logout(){  //退出登录
            console.log(11);
            localStorage.removeItem('token')
            localStorage.removeItem('userid')
            //  跳转到 登录页
            // this.$router.push('/login')
            // push 后回退还是回来个人中心, 但是由于已经退出登录
            // 数据获取就会报错, 应该用 replace 替换当前的个人中心记录
            this.$router.replace('/')
        },
        attention(){   //跳到关注页
            this.$router.push('/attention')
        },
        collect(){     //到收藏页
            this.$router.push('/collect')
        },
        myfollow(){   //到我的跟帖
            this.$router.push('/follow')
        },
        column(){
            this.$router.push('/columns')
        }
    }
}
</script>

<style lang="less" scoped>
    .personal{
        font-size: 15/360*100vw;
        font-weight: 400;
        background: #f2f2f2;
        width: 100%;
        height: 100%;
        .top{
            display: flex;
            text-align: left;
            margin-bottom: 20/360*100vw;
            div{
                line-height: 45/360*100vw;
                width: 64%;
                font-size: 15/360*100vw;
                font-weight: 700;
            }
            div:nth-child(1){
                width: 38%;
                padding-left: 15/360*100vw;
            }
        }
        .box{
            height: 130/360*100vw;
            width: 100%;
            border-bottom: solid 8px #e4e4e4;
            display: flex;

            .boxone{ //头部头像名称
                flex: 1;
                display: flex;
                align-items: center;
                justify-content: center;
                padding: 20/360*100vw;
                .message{
                    flex: 1;
                    display: flex;
                    align-items: center;
                    img{
                        width: 80/360*100vw;
                        height: 80/360*100vw;
                        //background: yellow;
                        object-fit: cover;
                        border-radius: 50%;
                    }
                    .mess{
                        span{
                            color: #7bbcec;
                            font-size: 13/360*100vw;
                        }
                        samp{
                            font-size: 15/360*100vw;
                        }
                    }
                }
            }

            .boxtwo{
                line-height: 130/360*100vw;
                text-align: right;
                padding-right: 20/360*100vw;
                span{
                    font-size: 30/360*100vw;
                }
            }
        }
    }
</style>